package com.zlop.common.dto;

import java.io.Serializable;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.zlop.common.enums.ResultCode;

/**
 * 响应结果消息
 *
 * @author  曾令鹏
 * @since   jdk1.8
 * @version 2018年4月8日 曾令鹏
 */
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result implements Serializable{

	private static final long serialVersionUID = -3251721328990152019L;
	
	private static final String EMPTY_DATA = "";
	
	/**
	 * 响应状态码   参考 ResultCode
	 */
	private int code;
	
	/**
	 * 响应提示信息
	 */
	private String msg;	
	
	/**
	 * 响应数据
	 */
	private Object data; 
	
	/**
	 * 执行成功
	 */
	public static Result success(){
		return Result.success(ResultCode.SUCCESS.msg());
	}
	
	public static Result success(String msg){
		return Result.success(msg, EMPTY_DATA);
	}
	
	public static Result success(String msg, Object data){
		return bulid(ResultCode.SUCCESS.code(), msg, data);
	}
	
	/**
	 * 执行失败
	 */
	public static Result error(){
		return Result.error(ResultCode.FAIL.msg());
	}
	
	public static Result error(String msg){
		return Result.error(msg, EMPTY_DATA);
	}
	
	public static Result error(String msg, Object data){
		return bulid(ResultCode.FAIL.code(), msg, data);
	}
	
	/**
	 * 暂无数据
	 */
	public static Result empty(){
		return Result.empty(ResultCode.EMPTY.msg());
	}
	
	public static Result empty(String msg){
		return Result.empty(msg, EMPTY_DATA);
	}
	
	public static Result empty(String msg, Object data){
		return bulid(ResultCode.EMPTY.code(), msg, data);
	}
	
	/**
	 * 构建实例对象
	 */
	private static Result bulid(int code, String msg, Object data){
		return new Result(code, msg, data);
	}
}
